package com.example.test;

import java.util.List;
import java.util.Vector;

import com.example.sms_emoticon_library.FragmentEmoticons;
import com.example.sms_emoticon_library.FragmentEmoticons.EmoticonsOnCLick;
import com.example.sms_emoticon_library.FragmentFuntions.FuntionsOnClick;


import com.example.sms_emoticon_library.FragmentFuntions;

import com.example.sms_emoticon_library.PagerAdapter;
import com.example.sms_emoticon_library.SmileyParser;


import com.example.test.R;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends FragmentActivity implements EmoticonsOnCLick, FuntionsOnClick {
	PagerAdapter mPagerAdapter;
	private String myString;
	EditText edtSms;
	
	private SmileyParser sp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		SmileyParser.init(getApplicationContext());
		sp= SmileyParser.getInstance();
		edtSms =  (EditText) findViewById(R.id.editText1);
		
		initFragmentViewPage();
		
		
		//Toast.makeText(this, myString, Toast.LENGTH_SHORT).show();
		//Toast.makeText(this, Toast.LENGTH_SHORT).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	private void initFragmentViewPage() {
		// TODO Auto-generated method stub
		List<Fragment> fragments= new Vector<Fragment>();
		fragments.add(Fragment.instantiate(this, FragmentFuntions.class.getName()));
		fragments.add(Fragment.instantiate(this, FragmentEmoticons.class.getName()));
		mPagerAdapter =  new PagerAdapter(this.getSupportFragmentManager(), fragments);
		ViewPager mViewPager= (ViewPager) findViewById(R.id.viewpager);
		mViewPager.setAdapter(mPagerAdapter);
		mViewPager.setCurrentItem(1);

	}

	
//Implement interface of FragmentEmoticons.............................	
	@Override
	public void buttonCLick(String link) {
		// TODO Auto-generated method stub
		Toast.makeText(this, link, Toast.LENGTH_SHORT).show();
	}
	@Override
	public void gvClick(String item) {
		// TODO Auto-generated method stub
		myString=item;
	
		
		String mBodyString= edtSms.getText().toString()+myString;
		CharSequence a = sp.addSmileySpans(mBodyString);
		edtSms.setText(a);
	}

	@Override
	public void ibGalarryOnClick(String path, String text) {
		// TODO Auto-generated method stub
		Toast.makeText(this,"Đường dẫn : "+ path + "\n Mô tả: "+text  , Toast.LENGTH_SHORT).show();
	}

	@Override
	public void ibCurrentLocation(Double longitude, Double latitude) {
		// TODO Auto-generated method stub
		Toast.makeText(this, "vi tri :"+longitude +"- "+latitude, Toast.LENGTH_SHORT).show();
	}

	


	
}
